package anji.plus.system.mark.service.impl;
import java.text.DecimalFormat;
import java.util.List;
import java.util.ArrayList;

import anji.plus.system.mark.controller.SysUserController;
import anji.plus.system.mark.response.ResponseCode;
import anji.plus.system.mark.base.BaseController;
import anji.plus.system.mark.base.BaseServiceImpl;
import anji.plus.system.mark.base.Header;
import anji.plus.system.mark.domain.SysUser;
import anji.plus.system.mark.domain.TaskList;
import anji.plus.system.mark.domain.TaskNodeList;
import anji.plus.system.mark.dto.RankInfo;
//import anji.plus.system.mark.dto.TaskListAndNode;
import anji.plus.system.mark.exception.BusinessException;
import anji.plus.system.mark.mapper.TaskListMapper;
import anji.plus.system.mark.response.ResponseCode;
import anji.plus.system.mark.response.ResponseResult;
import anji.plus.system.mark.service.ITaskListService;
import anji.plus.system.mark.utils.LoginUtils;
import anji.plus.system.mark.vo.*;
import cn.hutool.core.util.StrUtil;
import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate;
import java.util.*;


/**
 * <p>
 * 任务表 服务实现类
 * </p>
 *
 * @author luwei
 * @since 2023-11-08
 */
@Service
public class TaskListServiceImpl extends BaseServiceImpl<TaskListMapper, TaskList> implements ITaskListService {

    private static long[] ls = new long[3000];
    private static int li = 0;

    //    @Override
//    public void taskCompleteUpdate(TaskListVoCompleteUpdate taskListVoCompleteUpdate) {
//       taskListMapper.completeReviewUpdate(taskListVoCompleteUpdate);
//    }

    /**
     * @return long 返回long 主键内容
     * @Title: getPK
     * @Description: 主键生成方法，生成Long型的数字主键
     * @author: 温泉
     * @date 2012-08-02 09:56:37 +0800
     */
    public synchronized static long getPK() {
        /*
         * 2012-10-18 苏沫予： 修改主键生成算法，使主键在软件生命周期内具有时间连续性同时适应JS
         * 前端应用，根据当前算法，至少17年内不会发生2^53溢出问题 - 关于性能问题：
         * 新主键方案每10毫秒内有十万分之一的可能性会发生冲突主键问题，因此
         * 当系统每秒数据生成量达到100条时生成器实际性能大约下降0.003%，此
         * 后呈线性下降，每秒数据生成量150000条时，主键生成性能大约下降一倍， 每秒生成数据超过300000条后，该主键生成算法将不再安全 -
         * 关于并发问题： 该算法并发运行时（例如分布式服务器系统）存在每秒千万分之一的冲突
         * 可能性，因此建议不用于并发式系统，即便投入应用，也应当保证每秒并 发插入数据不超过1000条。
         */
        String a = String.valueOf((System.currentTimeMillis() / 10L) % 100000000000L);
        String d = (String.valueOf((1 + Math.random()) * 100000)).substring(1, 6);
        // 苏沫予：添加代码结束（同时移除韩欣宇的代码方案）
        long lo = Long.parseLong(a + d);
        for (int i = 0; i < 3000; i++) {
            long lt = ls[i];
            if (lt == lo) {
                lo = getPK();
                break;
            }
        }
        ls[li] = lo;
        li++;
        if (li == 3000) {
            li = 0;
        }
        return lo;
    }


    @Resource
    private TaskListMapper taskListMapper;
    private static Log log = LogFactory.get(TaskListServiceImpl.class);

    @Override
    public List<TaskList> queryTaskList(String name, LocalDate monthFirstDay, LocalDate nextMonthFirstDay, String departNum) {

        return taskListMapper.queryTaskList(name, monthFirstDay, nextMonthFirstDay, departNum);
    }


    @Override
    public TaskList ConfirmReviewFail(String taskId, String confirmReviewUser, String reviewStatus, String confirmReason, String isChange) {
        return taskListMapper.ConfirmReviewFail(taskId, confirmReviewUser, reviewStatus, confirmReason, isChange);
    }


    @Override
    public TaskList ConfirmReviewPass(String taskId, String confirmReviewUser, String reviewStatus, String confirmReason, String isChange) {
        return taskListMapper.ConfirmReviewPass(taskId, confirmReviewUser, reviewStatus, confirmReason, isChange);
    }


    @Override
    public TaskList ConfirmChange(String taskId, String changeReviewUser, String reviewStatus, String confirmChangeMark, String isChange) {
        return taskListMapper.ConfirmChange(taskId, changeReviewUser, reviewStatus, confirmChangeMark, isChange);
    }


    @Transactional(rollbackFor = Exception.class)
    @Override
    public void addTask(TaskListVo taskListVo) {
        if (taskListVo == null) {
            throw new BusinessException("参数不能为空");
        } else if (StrUtil.isEmpty(taskListVo.getTaskName())) {
            throw new BusinessException("任务名称不能为空");
        } else if (StrUtil.isEmpty(taskListVo.getCreateUserName())) {
            throw new BusinessException("任务提交审核-审核人不能为空");
        } else if (StrUtil.isEmpty(taskListVo.getScheduleTime())) {
            throw new BusinessException("任务提交审核-总任务计划工时不能为空");
        } else if (taskListVo.getNodeList() == null || taskListVo.getNodeList().size() == 0) {
            throw new BusinessException("节点信息不全");
        }
        TaskList taskList = new TaskList();
        taskList.setId(getPK());
        taskList.setScheduleTime(taskListVo.getScheduleTime());
        taskList.setTaskName(taskListVo.getTaskName());
        taskList.setTaskEndTime(taskListVo.getTaskEndTime());
        taskList.setCreateUserName(taskListVo.getCreateUserName());
        taskList.setConfirmReviewUser(taskListVo.getConfirmReviewUser());
        taskList.setMainMark(taskListVo.getMainMark());
        taskListMapper.addTask(taskList);
        List<TaskListNode> listNodes = taskListVo.getNodeList();
        for (TaskListNode t : listNodes
        ) {
            TaskNodeList taskNodeList = new TaskNodeList();
            taskNodeList.setTaskId(taskList.getId());
            taskNodeList.setNodeName(t.getNodeName());
            taskNodeList.setNodeEndTime(t.getNodeEndTime());
            taskNodeList.setNodeOrderId(t.getNodeOrderId());
            taskNodeList.setChildMark(t.getChildMark());
            taskListMapper.addTaskNode(taskNodeList);
        }
//        log.info(taskListVo.getCreateUserName()+"任务新增成功，任务名称是"+taskListVo.getTaskName());
    }

    @Override
    public List<TaskList> queryNeedReviewTask(String name) {
        if (name == null) {
            throw new BusinessException("参数不能为空");
        } else if (name == "") {
            throw new BusinessException("参数不能为空");
        } else {
            return taskListMapper.queryNeedReviewTask(name);
        }
    }

    @Override
    public List<TaskList> queryWaitReviewTask(String name) {
        if (name == null) {
            throw new BusinessException("参数不能为空");
        } else if (name == "") {
            throw new BusinessException("参数不能为空");
        } else {
            return taskListMapper.queryWaitReviewTask(name);
        }
    }

    @Override
    public List<TaskList> queryRejectTask(String name) {
        if (name == null) {
            throw new BusinessException("参数不能为空");
        } else if (name == "") {
            throw new BusinessException("参数不能为空");
        } else {
            return taskListMapper.queryRejectTask(name);
        }
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void taskUpdate(TaskListVoUpdate taskListVoUpdate) {
        List<TaskListNodeTwo> taskListNodeTwo = taskListVoUpdate.getNodeUpdateList();
        for (TaskListNodeTwo t : taskListNodeTwo
        ) {
            //获取任务评分
            Double nodeScore = 0.00;
            if ((Double.parseDouble(t.getNodeProgress()) > 50) && (Double.parseDouble(t.getNodeProgress()) < 100)) {
                nodeScore = 50.00;
            } else if ((Double.parseDouble(t.getNodeProgress()) >= 0) && (Double.parseDouble(t.getNodeProgress()) <= 50)) {
                nodeScore = Double.parseDouble(t.getNodeProgress());
            } else if (Math.abs(Double.parseDouble(t.getNodeProgress()) - 100) < 0.000001) {
                nodeScore = 100.00;
            } else {
                nodeScore = 100.00;
            }
            //获取任务编号
            long taskId = taskListVoUpdate.getTaskId();
            //获取节点进度
            String nodeProgress = t.getNodeProgress();
            //获取节点编号
            String nodeOrderId = t.getNodeOrderId();
            taskListMapper.nodeUpdate(taskId, nodeOrderId, nodeProgress, nodeScore);
        }
        //获取任务编号
        long taskId = taskListVoUpdate.getTaskId();
        String taskStatus = taskListVoUpdate.getTaskState();
        Double taskScore = 0.00;
        String completeReviewUser = taskListVoUpdate.getCompleteReviewUser();
        String reviewTheNote = taskListVoUpdate.getReviewTheNote();
        taskScore = taskListMapper.taskScoreCount(taskId);
        taskListMapper.taskUpdate(taskId, taskStatus, taskScore, completeReviewUser, reviewTheNote);
    }

    @Override
    public void NodeCompleteUpdate(TaskListVoCompleteUpdate taskListVoCompleteUpdate) {
        List<TaskListNodeTwo> taskListNodeTwo = taskListVoCompleteUpdate.getTaskListNodeTwoList();
        System.out.println("***完成审核更新节点进度开始****");
        for (int i = 0; i < taskListNodeTwo.size(); i++) {
            Long taskID = taskListVoCompleteUpdate.getTaskId();
            String nodeOrderID = taskListNodeTwo.get(i).getNodeOrderId();
            String nodeProgress = taskListNodeTwo.get(i).getNodeProgress();
            taskListMapper.taskNodeUpdate(taskID, nodeOrderID, nodeProgress);
        }
        System.out.println("***完成审核更新节点进度结束**");
    }


    @Override
    public Double queryUserScore(String name, LocalDate monthFirstDate, LocalDate nextMonthfirstday) {
        Integer qTaskNum = taskListMapper.queryUserTaskNum(name, monthFirstDate, nextMonthfirstday);
        Double qScore = 0.00;

        if (qTaskNum == null) {
            qTaskNum = 0;
            qScore = 0.00;
        } else if (qTaskNum == 0) {
            qScore = 0.00;
        } else if (qTaskNum <= 4) {
            int t1 = 0;
            List<Double> nodeScoreList = new ArrayList<>();
            nodeScoreList = taskListMapper.queryUserAllScore(name, monthFirstDate, nextMonthfirstday);
            t1 = nodeScoreList.size();
            qScore = 25 * t1 * (taskListMapper.queryUserScore(name, monthFirstDate, nextMonthfirstday)) / 100;
        } else {
            qScore = taskListMapper.queryUserScore(name, monthFirstDate, nextMonthfirstday);
        }
        DecimalFormat df = new DecimalFormat("#.00");
        String f1 = df.format(qScore);
        return Double.valueOf(f1);
    }

    @Override
    public Double queryUserScoreNew(String name, LocalDate monthFirstDate, LocalDate nextMonthfirstday) {
        Integer qTaskNum = taskListMapper.queryUserTaskNum(name, monthFirstDate, nextMonthfirstday);
        Double qScore = 0.00;

        if (qTaskNum == null) {
            qTaskNum = 0;
            qScore = 0.00;
        } else if (qTaskNum == 0) {
            qScore = 0.00;
        } else if (qTaskNum <= 4) {
            int t1 = 0;
            List<Double> nodeScoreList = new ArrayList<>();
            nodeScoreList = taskListMapper.queryUserAllScore(name, monthFirstDate, nextMonthfirstday);
            t1 = nodeScoreList.size();
            qScore = 25 * t1 * (taskListMapper.queryUserScore(name, monthFirstDate, nextMonthfirstday)) / 100;
        } else {
            qScore = taskListMapper.queryUserScore(name, monthFirstDate, nextMonthfirstday);
        }
        return qScore;
    }


    @Override
    public Integer queryUserTaskNum(String name, LocalDate monthFirstDate, LocalDate nextMonthfirstday) {
        Integer qTaskNum = taskListMapper.queryUserTaskNum(name, monthFirstDate, nextMonthfirstday);
        if (qTaskNum == null) {
            qTaskNum = 0;
        }
        return qTaskNum;
    }

    @Override
    public List<RankInfo> userScoreRankNew(LocalDate monthFirstDay, LocalDate nextMonthfirstday) {
        List<String> list = Arrays.asList("陆如华", "陈建明", "周冲", "高晓龙", "来青原", "李辉", "刘津津", "卢威", "孟令雪", "彭旭峰","刘综南","肖泽文");
        List<RankInfo> list1;


        for (String element : list) {
            String name = element;
            System.out.println(element);
            Double qScore = queryUserScore(name, monthFirstDay, nextMonthfirstday);
            if (qScore == null) {
                qScore = 0.00;
            }
            System.out.println(name);
            System.out.println(qScore);
        }
        System.out.println(taskListMapper.userScoreRank(monthFirstDay, nextMonthfirstday));

        return taskListMapper.userScoreRank(monthFirstDay, nextMonthfirstday);
    }


    @Override
    public List<RankInfo> userScoreRank(LocalDate monthFirstDay, LocalDate nextMonthfirstday) {
        //list 是接口，不是实体类
        List<RankInfo> lr = new ArrayList<>();
        List<String> list = Arrays.asList("陈建明", "赵莹", "周冲", "高晓龙", "来青原", "李辉", "刘津津", "卢威", "孟令雪", "彭旭峰",
                "陈中伟", "李杰", "倪敬伟", "阮思哲", "孙书怡", "王琳", "杨光鹏", "周骏", "尤优","刘综南","肖泽文"
        );
        for (String element : list) {
            RankInfo rankInfo = new RankInfo();
            rankInfo.setUserName(element);
            rankInfo.setTaskCount(queryUserTaskNum(element, monthFirstDay, nextMonthfirstday));
            rankInfo.setTaskScore(Double.valueOf(queryUserScore(element, monthFirstDay, nextMonthfirstday)));
            lr.add(rankInfo);
        }

        System.out.println("***********************************");
        lr.forEach(item -> System.out.println(item));
        System.out.println("***********************************");
//        lr.sort(Comparator.comparing(RankInfo::getTaskScore).reversed().thenComparing(RankInfo::getTaskCount).reversed().thenComparing(RankInfo::getUserName).reversed());
//        lr.sort(Comparator.comparingDouble(RankInfo::getTaskScore).thenComparingInt(RankInfo::getTaskCount).reversed().thenComparing(RankInfo::getUserName));
        lr.sort(Comparator.comparingDouble(RankInfo::getTaskScore).thenComparingInt(RankInfo::getTaskCount).reversed());
        lr.forEach(item -> System.out.println(item));
        System.out.println("***********************************");


//      针对 lr 中 serName，TaskCount，TaskScore 三个元素排序，分数，任务，名字，都按DESC排序后，

//      并复制到新的LIST对象z,程序返回值返回该对象z；
        return lr;
//        return taskListMapper.userScoreRank(monthFirstDay,nextMonthfirstday);
    }

    @Override
    public Double queryUserScheduleTime(String name, LocalDate monthFirstDate, LocalDate nextMonthfirstday) {
        Double qTimeNum = 0.00;
        qTimeNum = taskListMapper.queryUserScheduleTime(name, monthFirstDate, nextMonthfirstday);
        return qTimeNum;
    }


    @Override
    public void jobTaskUpdate() {
        LocalDate currentDate = LocalDate.now();

        taskListMapper.jobsUpdateExpiredTask(currentDate);

    }

    @Override
    public IndexQuery indexQuery(String name, LocalDate monthFirstDate, LocalDate nextMonthfirstday, String departNum) {

        Integer qTaskNum = taskListMapper.queryUserTaskNum(name, monthFirstDate, nextMonthfirstday);
        if (qTaskNum == null) {
            qTaskNum = 0;
        }
        Double qScore = 0.00;
        if (qTaskNum == 0) {
            qScore = 0.00;
        } else if (qTaskNum <= 4) {
            int t1 = 0;
            List<Double> nodeScoreList = new ArrayList<>();
            nodeScoreList = taskListMapper.queryUserAllScore(name, monthFirstDate, nextMonthfirstday);
            t1 = nodeScoreList.size();
            qScore = 25 * t1 * (taskListMapper.queryUserScore(name, monthFirstDate, nextMonthfirstday)) / 100;
        } else {
            qScore = taskListMapper.queryUserScore(name, monthFirstDate, nextMonthfirstday);
        }
        IndexQuery indexQuery = new IndexQuery();
        indexQuery.setQScore(qScore);
        indexQuery.setQTaskNum(qTaskNum);
        indexQuery.setRankInfoList(userScoreRank2(monthFirstDate, nextMonthfirstday,departNum));
        return indexQuery;
    }

    @Override
    public IndexQuery indexQueryNew(String name, LocalDate monthFirstDate, LocalDate nextMonthfirstday) {
        Integer qTaskNum = taskListMapper.queryUserTaskNum(name, monthFirstDate, nextMonthfirstday);
        if (qTaskNum == null) {
            qTaskNum = 0;
        }
        Double qScore = 0.00;
        if (qTaskNum == 0) {
            qScore = 0.00;
        } else if (qTaskNum <= 4) {
            int t1 = 0;
            List<Double> nodeScoreList = new ArrayList<>();
            nodeScoreList = taskListMapper.queryUserAllScore(name, monthFirstDate, nextMonthfirstday);
            t1 = nodeScoreList.size();
            qScore = 25 * t1 * (taskListMapper.queryUserScore(name, monthFirstDate, nextMonthfirstday)) / 100;
        } else {
            qScore = taskListMapper.queryUserScore(name, monthFirstDate, nextMonthfirstday);
        }
        IndexQuery indexQuery = new IndexQuery();
        indexQuery.setQScore(qScore);
        indexQuery.setQTaskNum(qTaskNum);
        indexQuery.setRankInfoList(userScoreRank(monthFirstDate, nextMonthfirstday));
        return indexQuery;
    }


    @Override
    public TaskList completeReviewPass(String taskId, String completeReviewUser, String reviewStatus, String completeReason, String isChange) {
        return taskListMapper.completeReviewPass(taskId, completeReviewUser, reviewStatus, completeReason, isChange);
    }

    @Override
    public TaskList completeReviewFail(String taskId, String completeReviewUser, String reviewStatus, String completeReason, String isChange) {
        return taskListMapper.completeReviewFail(taskId, completeReviewUser, reviewStatus, completeReason, isChange);
    }

    @Override
    public TaskList completeChange(String taskId, String changeReviewUser, String reviewStatus, String completeChangeMark, String isChange) {
        return taskListMapper.completeChange(taskId, changeReviewUser, reviewStatus, completeChangeMark, isChange);
    }


    @Override
    public void scoreUpdate(TaskListVoCompleteUpdate taskListVoCompleteUpdate) {
        List<TaskListNodeTwo> taskListNodeTwo = taskListVoCompleteUpdate.getTaskListNodeTwoList();

        for (TaskListNodeTwo t : taskListNodeTwo
        ) {
            //获取任务评分
            Double nodeScore = 0.00;
            if ((Double.parseDouble(t.getNodeProgress()) > 50) && (Double.parseDouble(t.getNodeProgress()) < 100)) {
                nodeScore = 50.00;
            } else if ((Double.parseDouble(t.getNodeProgress()) >= 0) && (Double.parseDouble(t.getNodeProgress()) <= 50)) {
                nodeScore = Double.parseDouble(t.getNodeProgress());
            } else if (Math.abs(Double.parseDouble(t.getNodeProgress()) - 100) < 0.000001) {
                nodeScore = 100.00;
            } else {
                nodeScore = 100.00;
            }
            //获取任务编号
            long taskId = taskListVoCompleteUpdate.getTaskId();
            //获取节点进度
            String nodeProgress = t.getNodeProgress();
            //获取节点编号
            String nodeOrderId = t.getNodeOrderId();
            taskListMapper.nodeUpdate(taskId, nodeOrderId, nodeProgress, nodeScore);
        }
        //获取任务编号
        long taskId = taskListVoCompleteUpdate.getTaskId();
        String taskStatus = taskListVoCompleteUpdate.getReviewStatus();
        Double taskScore = 0.00;
        String completeReviewUser = taskListVoCompleteUpdate.getCompleteReviewUser();
        String reviewTheNote = taskListVoCompleteUpdate.getReviewTheNote();
        taskScore = taskListMapper.taskScoreCount(taskId);
        taskListMapper.taskUpdate(taskId, taskStatus, taskScore, completeReviewUser, reviewTheNote);
    }

    @Override
    public List<RankInfo> userScoreRank2(LocalDate monthFirstDay, LocalDate nextMonthfirstday, String departNum) {
        //list 是接口，不是实体类
        List<RankInfo> lr = new ArrayList<>();
        List<String> list1 = Arrays.asList("陈建明", "周冲", "高晓龙", "来青原", "李辉", "刘津津", "卢威", "孟令雪", "彭旭峰",
                "尤优","刘综南","肖泽文"
        );
        List<String> list2 = Arrays.asList(
                "陈中伟", "李杰", "倪敬伟", "阮思哲", "孙书怡", "王琳", "杨光鹏", "周骏"
        );
        if (departNum.equals("1")){
            for (String element : list1) {
                RankInfo rankInfo = new RankInfo();
                rankInfo.setUserName(element);
                rankInfo.setTaskTimeNum(queryUserScheduleTime(element,monthFirstDay,nextMonthfirstday));
                rankInfo.setTaskCount(queryUserTaskNum(element, monthFirstDay, nextMonthfirstday));
                rankInfo.setTaskScore(Double.valueOf(queryUserScore(element, monthFirstDay, nextMonthfirstday)));
                rankInfo.setTaskNumIsEnough(queryUserTaskNumIsEnough(element, monthFirstDay, nextMonthfirstday));
                lr.add(rankInfo);
            }
            System.out.println("***********************************");
            lr.forEach(item -> System.out.println(item));
            System.out.println("***********************************");
//        lr.sort(Comparator.comparing(RankInfo::getTaskScore).reversed().thenComparing(RankInfo::getTaskCount).reversed().thenComparing(RankInfo::getUserName).reversed());
//        lr.sort(Comparator.comparingDouble(RankInfo::getTaskScore).thenComparingInt(RankInfo::getTaskCount).reversed().thenComparing(RankInfo::getUserName));
//            按分数，任务数 倒叙排序
//            lr.sort(Comparator.comparingDouble(RankInfo::getTaskScore).thenComparingInt(RankInfo::getTaskCount).reversed());
//          按分数，任务数，工时 倒叙排序
            lr.sort(Comparator.comparingDouble(RankInfo::getTaskScore).thenComparingInt(RankInfo::getTaskCount).thenComparingDouble(RankInfo::getTaskTimeNum).reversed());
            lr.forEach(item -> System.out.println(item));
            System.out.println("***********************************");
            return lr;
        } else{
            for (String element : list2) {
                RankInfo rankInfo = new RankInfo();
                rankInfo.setUserName(element);
                rankInfo.setTaskCount(queryUserTaskNum(element, monthFirstDay, nextMonthfirstday));
                rankInfo.setTaskScore(Double.valueOf(queryUserScore(element, monthFirstDay, nextMonthfirstday)));
                lr.add(rankInfo);
            }
            System.out.println("***********************************");
            lr.forEach(item -> System.out.println(item));
            System.out.println("***********************************");
//        lr.sort(Comparator.comparing(RankInfo::getTaskScore).reversed().thenComparing(RankInfo::getTaskCount).reversed().thenComparing(RankInfo::getUserName).reversed());
//        lr.sort(Comparator.comparingDouble(RankInfo::getTaskScore).thenComparingInt(RankInfo::getTaskCount).reversed().thenComparing(RankInfo::getUserName));
            lr.sort(Comparator.comparingDouble(RankInfo::getTaskScore).thenComparingInt(RankInfo::getTaskCount).reversed());
            lr.forEach(item -> System.out.println(item));
            System.out.println("***********************************");
            return lr;
    }
}


    private String queryUserTaskNumIsEnough(String element, LocalDate monthFirstDay, LocalDate nextMonthfirstday) {
        String  t1 = taskListMapper.queryUserTaskNumIsEnough(element, monthFirstDay, nextMonthfirstday);
        String taskNumIsEnough;
        int a1 = Integer.parseInt(t1);
        if (a1 < 3) {
            taskNumIsEnough = "0";
        }else{
            taskNumIsEnough = "1";
        }
        return taskNumIsEnough;
    }


    @Override
    public List<RankInfo> indexQuerypc(String name, LocalDate monthFirstDate, LocalDate nextMonthfirstday, String departNum) {

        return userScoreRank2pc(name,monthFirstDate, nextMonthfirstday,departNum);
    }


    @Override
    public List<RankInfo> userScoreRank2pc(String name, LocalDate monthFirstDay, LocalDate nextMonthfirstday, String departNum) {
        //list 是接口，不是实体类
        List<RankInfo> lr = new ArrayList<>();
        List<String> list1 = Arrays.asList(
                "陈建明", "周冲", "高晓龙", "来青原", "李辉", "刘津津", "卢威", "孟令雪", "彭旭峰", "尤优","刘综南","肖泽文"
        );
        List<String> list2 = Arrays.asList(
                "陈中伟", "李杰", "倪敬伟", "阮思哲", "孙书怡", "王琳", "杨光鹏", "周骏"
        );
        if ((name == null)||(name == "")){
            for (String element : list1) {
                RankInfo rankInfo = new RankInfo();
                rankInfo.setUserName(element);
                rankInfo.setTaskTimeNum(queryUserScheduleTime(element,monthFirstDay,nextMonthfirstday));
                rankInfo.setTaskCount(queryUserTaskNum(element, monthFirstDay, nextMonthfirstday));
                rankInfo.setTaskScore(Double.valueOf(queryUserScore(element, monthFirstDay, nextMonthfirstday)));
                rankInfo.setTaskNumIsEnough(queryUserTaskNumIsEnough(element, monthFirstDay, nextMonthfirstday));
                lr.add(rankInfo);
            }
            System.out.println("***********************************");
            lr.forEach(item -> System.out.println(item));
            System.out.println("***********************************");
//        lr.sort(Comparator.comparing(RankInfo::getTaskScore).reversed().thenComparing(RankInfo::getTaskCount).reversed().thenComparing(RankInfo::getUserName).reversed());
//        lr.sort(Comparator.comparingDouble(RankInfo::getTaskScore).thenComparingInt(RankInfo::getTaskCount).reversed().thenComparing(RankInfo::getUserName));
//            按分数，任务数 倒叙排序
//            lr.sort(Comparator.comparingDouble(RankInfo::getTaskScore).thenComparingInt(RankInfo::getTaskCount).reversed());
//          按分数，任务数，工时 倒叙排序
            lr.sort(Comparator.comparingDouble(RankInfo::getTaskScore).thenComparingInt(RankInfo::getTaskCount).thenComparingDouble(RankInfo::getTaskTimeNum).reversed());
            lr.forEach(item -> System.out.println(item));
            System.out.println("***********************************");
            // 获取前3个元素
            List<RankInfo> firstThree = lr.subList(0, Math.min(lr.size(), 3));
            System.out.println("前3个元素: " + firstThree);

            // 获取后3个元素
            List<RankInfo> lastThree = lr.subList(Math.max(lr.size() - 3, 0), lr.size());
            System.out.println("后3个元素: " + lastThree);
            return lr;
        } else if (name.equals("陈建明")||name.equals("周冲")||name.equals("高晓龙")||name.equals("来青原")||name.equals("李辉")||name.equals("刘津津")||
                name.equals("卢威")||name.equals("孟令雪")||name.equals("彭旭峰")||name.equals("尤优")){
                RankInfo rankInfo = new RankInfo();
                rankInfo.setUserName(name);
                rankInfo.setTaskTimeNum(queryUserScheduleTime(name,monthFirstDay,nextMonthfirstday));
                rankInfo.setTaskCount(queryUserTaskNum(name, monthFirstDay, nextMonthfirstday));
                rankInfo.setTaskScore(Double.valueOf(queryUserScore(name, monthFirstDay, nextMonthfirstday)));
                rankInfo.setTaskNumIsEnough(queryUserTaskNumIsEnough(name, monthFirstDay, nextMonthfirstday));
                lr.add(rankInfo);

            System.out.println("***********************************");
            lr.forEach(item -> System.out.println(item));
            System.out.println("***********************************");
//        lr.sort(Comparator.comparing(RankInfo::getTaskScore).reversed().thenComparing(RankInfo::getTaskCount).reversed().thenComparing(RankInfo::getUserName).reversed());
//        lr.sort(Comparator.comparingDouble(RankInfo::getTaskScore).thenComparingInt(RankInfo::getTaskCount).reversed().thenComparing(RankInfo::getUserName));
//        lr.sort(Comparator.comparingDouble(RankInfo::getTaskScore).thenComparingInt(RankInfo::getTaskCount).thenComparingDouble(RankInfo::getTaskTimeNum).reversed());
            lr.forEach(item -> System.out.println(item));
            System.out.println("***********************************");
            return lr;
        }else {
            List<RankInfo> lr1 = new ArrayList<>();
            return lr1;
        }

    }
}

